{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ac0b5c32-6336-4a8d-8d2e-6c6c5eda6f0f",
   "metadata": {},
   "source": [
    "# 下载Qwen2-7B-Instruct开源大模型\n",
    "\n",
    "同济子豪兄 2024-9-8"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "09b643fd-04ac-41db-b267-0b441d36cac9",
   "metadata": {},
   "source": [
    "## 下载Qwen2-7B-Instruct模型文件\n",
    "\n",
    "https://huggingface.co/Qwen/Qwen2-7B-Instruct"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "21cf4e18-c0e1-4451-8e67-2bb089a4f7b3",
   "metadata": {},
   "source": [
    "## 将原生大模型量化压缩为INT4的OpenVINO IR模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6fcae10e-ecb0-4e67-a4ed-031a3622501c",
   "metadata": {},
   "outputs": [],
   "source": [
    "!optimum-cli export openvino \\\n",
    "             --model \"Qwen/Qwen2-7B-Instruct\" \\\n",
    "             --task text-generation-with-past \\\n",
    "             --weight-format int4 \\\n",
    "             --group-size 128 \\\n",
    "             --ratio 0.8 \\\n",
    "             \"Qwen2-7B-Instruct-int4-ov\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2ed747cc-450e-4153-83ba-cb4b381a8179",
   "metadata": {},
   "source": [
    "optimum库介绍：https://www.bilibili.com/video/BV1SQpceiEMh\n",
    "\n",
    "optimum-cli参数说明：https://huggingface.co/docs/optimum/intel/openvino/export"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "68f352e9-7956-4992-9dc5-0bad7c8268c7",
   "metadata": {},
   "source": [
    "## 也可直接下载我已经转换好的OpenVINO INT4 IR模型文件\n",
    "\n",
    "https://www.modelscope.cn/models/snake7gun/Qwen2-7B-Instruct-int4-ov"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7d01b95f-d07e-47a2-afca-4288c0d2536c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
